//
//  MyBoomInfoViewController.m
//  Liuhe
//
//  Created by zr on 2018/8/21.
//  Copyright © 2018年 zr. All rights reserved.
//

#import "MyBoomInfoViewController.h"

@interface MyBoomInfoViewController ()

@property (nonatomic, weak)UIImageView * topImageView;
@property (nonatomic, weak)UILabel * titleLabel;
@property (nonatomic, weak)UILabel * timeLabel;
@property (nonatomic, weak)UILabel * adressLabel;
@property (nonatomic, weak)UITextView * textView;
@property (nonatomic, weak)UIView * lineView;

@end

@implementation MyBoomInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = ColorWithRGB(0xF2F2F2);

    [self setupNav];
    [self setupUI];
}


- (void)setupNav{
    
    self.title = @"爆料详情";
    
    UIButton * backButton = [[UIButton alloc] init];
    
    backButton.frame = CGRectMake(0, 0, 12 * SCREENH6, 20 * SCREENH6);
    [backButton setImage:[UIImage imageNamed:@"1返回"] forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(backToView) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem * leftButton = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    
    self.navigationItem.leftBarButtonItem = leftButton;
    
}


- (void)setupUI{
    
    UILabel * titleLabel = [UILabel new];
    
    titleLabel.textColor = BLACK_COLOR;
    titleLabel.font = [UIFont systemFontOfSize:17 * SCREENH6];
    titleLabel.text = self.model.title;
    titleLabel.numberOfLines = 0;
    
    self.titleLabel = titleLabel;
    
    [self.view addSubview:self.titleLabel];
    
    UILabel * timeLabel = [UILabel new];
    
    timeLabel.textColor = [UIColor lightGrayColor];
    timeLabel.font = [UIFont systemFontOfSize:14 * SCREENH6];
    timeLabel.text = self.model.date;
    timeLabel.textAlignment = NSTextAlignmentRight;
    
    self.timeLabel = timeLabel;
    
    [self.view addSubview:self.timeLabel];
    

    UIView * lineView = [UIView new];
    
    lineView.backgroundColor = ColorWithRGB(0xe6e6e6);
    
    self.lineView = lineView;
    
    [self.view addSubview:self.lineView];
    
    
    UIImageView * topImageView = [UIImageView new];
    
    NSArray * arr = self.model.images;
    NSURL * url = [NSURL URLWithString:arr.firstObject];
    topImageView.contentMode = UIViewContentModeScaleAspectFit;
    
    [topImageView sd_setImageWithURL:url];
    
    self.topImageView = topImageView;
    
    [self.view addSubview:self.topImageView];
    
    
    UITextView *textView =[[UITextView alloc] init];
    textView.backgroundColor= [UIColor whiteColor];
    textView.text = self.model.content;
    textView.textColor = [UIColor blackColor];
    textView.editable = NO;
    textView.font = [UIFont systemFontOfSize:14 * SCREENH6];
    
    self.textView = textView;
    
    [self.view addSubview:self.textView];
}


- (void)viewDidLayoutSubviews{
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.view).offset(15 * SCREENH6);
        make.trailing.mas_equalTo(self.view).offset(-10 * SCREENH6);
        make.top.mas_equalTo(self.view).offset(10 * SCREENH6);
    }];
    
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self.titleLabel);
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(8 * SCREENH6);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.mas_equalTo(self.view);
        make.height.mas_equalTo(1 * SCREENH6);
        make.top.mas_equalTo(self.timeLabel.mas_bottom).offset(8 * SCREENH6);
    }];
    
    [self.topImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.view).offset(10 * SCREENH6);
        make.trailing.mas_equalTo(self.view).offset(-10 * SCREENH6);
        make.top.mas_equalTo(self.lineView.mas_bottom).offset(10 * SCREENH6);
        make.height.mas_equalTo(200 * SCREENH6);
    }];
    
    [self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.mas_equalTo(self.topImageView);
        make.bottom.mas_equalTo(self.view);
        make.top.mas_equalTo(self.topImageView.mas_bottom).offset(5 * SCREENH6);
    }];
}

- (void)backToView{
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
